package com.linhh.mall.center.web.controller;

import com.github.pagehelper.PageInfo;
import com.linhh.mall.center.api.RoleInfoService;
import com.linhh.mall.center.api.TemplateInfoService;
import com.linhh.mall.center.common.pojo.RoleInfo;
import com.linhh.mall.center.common.util.HttpResult;
import net.bytebuddy.agent.builder.AgentBuilder;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户角色控制层
 * @Author linhh
 * @Date 2023 01 11 15 20
 **/
@RestController
@RequestMapping("/api")
public class RoleInfoController {

    @Reference
    private RoleInfoService roleInfoService;

    /**
     * 查询所有角色信息
     * @param page
     * @param size
     * @return
     */
    @RequestMapping("/roleController/roleList")
    public HttpResult getRoleList(Integer page,Integer size){
        List<RoleInfo> roleInfoList = roleInfoService.selectAll();
        PageInfo<RoleInfo> roleInfoPageInfo = new PageInfo<>(roleInfoList);
        return HttpResult.success(roleInfoPageInfo);
    }

    /**
     * 添加
     * @param roleInfo
     * @return
     */
    @PostMapping("/roleController/addRole")
    public int addRole(@RequestBody RoleInfo roleInfo){
        System.out.println("RoleAdd");
        return roleInfoService.addRole(roleInfo);
    }

    /**
     * 更新、编辑
     * @param roleInfo
     * @return
     */
    @PutMapping("/roleController/roles")
    public int updateRole(@RequestBody RoleInfo roleInfo){
        System.out.println("updateRole");
        return roleInfoService.updateRole(roleInfo);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/roleController/roles/{id}")
    public int deleteRole(@PathVariable Long id){
        System.out.println("deleteRole");
        return roleInfoService.deleteRole(id);
    }
}
